package com.xtravel.discovery.widget;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import android.widget.GridView;
import android.widget.ListAdapter;

public class NoScrollGridViewEx extends GridView {
    public NoScrollGridViewEx(Context context) {
        super(context);
    }

    public NoScrollGridViewEx(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

    @Override
    public void setAdapter(ListAdapter adapter) {
        super.setAdapter(adapter);
//        DisplayMetrics dm = new DisplayMetrics();
//        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
//        android.view.ViewGroup.LayoutParams params = getLayoutParams();
//        WindowManager wm = ((Activity) getContext()).getWindowManager();
//        int width = wm.getDefaultDisplay().getWidth();
//        int imgWidth = (int) (width - ((24 + 7) * dm.density)) / this.getNumColumns();
//        params.width = (int) (imgWidth + 7 * dm.density) * getNumColumns();
//        params.height = LayoutParams.WRAP_CONTENT;
//        setLayoutParams(params);
//        Log.d("GridEx", "imgWidth:"  +imgWidth + "; width:" + width);
    }
}